home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // AutoRect.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "RRect.h"
- #include "AutoRect.h" // This class
- #include "RectPage.h" // Property page class
- #include "Imsigx.h" // TurboCAD interfaces
- #include <math.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- // Standard variants
- COleVariant t(-1L, VT_BOOL);
- COleVariant f(0L, VT_BOOL);
- COleVariant z(0.0);
- COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
- const double PI = 3.14159265;
-
- /////////////////////////////////////////////////////////////////////////////
- // CAutoRect
-
- const IID IID_IGraphic =
- {0x6A481109,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- IMPLEMENT_DYNCREATE(CAutoRect, CCmdTarget)
-
- CAutoRect::CAutoRect() :
- m_pRectPage(NULL)
- {
- EnableAutomation();
-
- // To keep the application running as long as an OLE automation
- // object is active, the constructor calls AfxOleLockApp.
-
- AfxOleLockApp();
- }
-
- CAutoRect::~CAutoRect()
- {
- // To terminate the application when all objects created with
- // with OLE automation, the destructor calls AfxOleUnlockApp.
-
- AfxOleUnlockApp();
- }
-
-
- void CAutoRect::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
-
- CCmdTarget::OnFinalRelease();
- }
-
-
- BEGIN_MESSAGE_MAP(CAutoRect, CCmdTarget)
- //{{AFX_MSG_MAP(CAutoRect)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- BEGIN_DISPATCH_MAP(CAutoRect, CCmdTarget)
- //{{AFX_DISPATCH_MAP(CAutoRect)
- DISP_PROPERTY_EX(CAutoRect, "ClassID", GetClassID, SetNotSupported, VT_BSTR)
- DISP_PROPERTY_EX(CAutoRect, "Description", GetDescription, SetNotSupported, VT_BSTR)
- DISP_FUNCTION(CAutoRect, "GetPropertyInfo", GetPropertyInfo, VT_I4, VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "GetPageInfo", GetPageInfo, VT_I4, VTS_DISPATCH VTS_PI4 VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "GetWizardInfo", GetWizardInfo, VT_I4, VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "GetEnumNames", GetEnumNames, VT_I4, VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "PageControls", PageControls, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_I4 VTS_BOOL)
- DISP_FUNCTION(CAutoRect, "PageDone", PageDone, VT_EMPTY, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "PropertyPages", PropertyPages, VT_BOOL, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "Wizard", Wizard, VT_BOOL, VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "OnGeometryChanged", OnGeometryChanged, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "OnGeometryChanging", OnGeometryChanging, VT_BOOL, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "OnNewGraphic", OnNewGraphic, VT_BOOL, VTS_DISPATCH VTS_BOOL)
- DISP_FUNCTION(CAutoRect, "OnCopyGraphic", OnCopyGraphic, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_VARIANT)
- DISP_FUNCTION(CAutoRect, "OnPropertyChanged", OnPropertyChanged, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "OnPropertyChanging", OnPropertyChanging, VT_BOOL, VTS_DISPATCH VTS_I4 VTS_PVARIANT VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "OnPropertyGet", OnPropertyGet, VT_EMPTY, VTS_DISPATCH VTS_I4)
- DISP_FUNCTION(CAutoRect, "Draw", Draw, VT_BOOL, VTS_DISPATCH VTS_DISPATCH VTS_PVARIANT)
- DISP_FUNCTION(CAutoRect, "Regen", Regen, VT_EMPTY, VTS_DISPATCH)
- DISP_FUNCTION(CAutoRect, "Initialize", Initialize, VT_BOOL, VTS_DISPATCH)
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
-
- // Note: we add support for IID_ISmartObjectServer to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
-
- static const IID IID_ISmartObjectServer =
- {0x6A481303,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- BEGIN_INTERFACE_MAP(CAutoRect, CCmdTarget)
- INTERFACE_PART(CAutoRect, IID_ISmartObjectServer, Dispatch)
- END_INTERFACE_MAP()
-
- IMPLEMENT_OLECREATE(CAutoRect, "RRect.Rectangle", 0x7724bb36, 0xb671, 0x11d0, 0x9b, 0x3b, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);//# Non-localizable string#
-
- /////////////////////////////////////////////////////////////////////////////
- // CAutoRect message handlers
-
- BSTR CAutoRect::GetClassID()
- {
- // Convert our GUID (see IMPLEMENT_OLECREATE macro) to a string
- LPOLESTR olestr;
- HRESULT hRes = ::StringFromCLSID(guid, &olestr);
- if (FAILED(hRes))
- return NULL;
-
- BSTR bstr = ::SysAllocString(olestr);
- CoTaskMemFree(olestr);
- return bstr;
- }
-
- BSTR CAutoRect::GetDescription()
- {
- // Get the description from the resource
- CString strResult;
- strResult.LoadString(IDS_AUTORECT_DESCRIPTION);
-
- return strResult.AllocSysString();
- }
-
- const long VT_INTEGER_ENUM = VT_I2 + 100;
- const long VT_LONG_ENUM = VT_I4 + 100;
- const long VT_STRING_ENUM = VT_BSTR + 100;
-
- const long GF_COSMETIC = 128;
-
- enum StockPages {
- PP_STOCK_PEN = 1,
- PP_STOCK_BRUSH = 2,
- PP_STOCK_TEXT = 4,
- PP_STOCK_INSERT = 8,
- PP_STOCK_VIEWPORT = 16,
- PP_STOCK_AUTO = 32
- };
-
- // our Rounded rectangle object has only one property called Roundess
- const long nProperties = 1;
- // define one property
- enum PropertyIDs
- {
- idRoundness = 1,
- };
-
- long CAutoRect::GetPropertyInfo(VARIANT FAR* Names, VARIANT FAR* Types, VARIANT FAR* IDs, VARIANT FAR* Defaults)
- {
- ASSERT(Names->vt == (VT_ARRAY|VT_BSTR));
- ASSERT(Types->vt == (VT_ARRAY|VT_I4));
- ASSERT(IDs->vt == (VT_ARRAY|VT_I4));
- ASSERT(Defaults->vt == (VT_ARRAY|VT_VARIANT));
-
- SAFEARRAYBOUND bound = { nProperties, 0 };
- if (FAILED(::SafeArrayRedim(Names->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(Types->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(IDs->parray, &bound)))
- return 0;
- if (FAILED(::SafeArrayRedim(Defaults->parray, &bound)))
- return 0;
-
- BSTR* rgNames;
- long* rgTypes;
- long* rgIDs;
- VARIANT* rgDefaults;
- long lReturn = 0;
- if (SUCCEEDED(::SafeArrayAccessData(Names->parray, (void**)&rgNames)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(Types->parray, (void**)&rgTypes)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(IDs->parray, (void**)&rgIDs)))
- {
- if (SUCCEEDED(::SafeArrayAccessData(Defaults->parray, (void**)&rgDefaults)))
- {
- CString strStr;
- strStr.LoadString(IDS_PROPERTYROUNDESS);
- //rgNames[0] = ::SysAllocString(OLESTR("Roundness"));//# Localizable string#
- rgNames[0] = ::SysAllocString(strStr.AllocSysString());
- rgTypes[0] = VT_R8;
- rgIDs[0] = idRoundness;
- rgDefaults[0].vt = VT_R8;
- rgDefaults[0].dblVal = 50.0;
-
- ::SafeArrayUnaccessData(Defaults->parray);
- lReturn = nProperties;
- }
- ::SafeArrayUnaccessData(IDs->parray);
- }
- ::SafeArrayUnaccessData(Types->parray);
- }
- ::SafeArrayUnaccessData(Names->parray);
- }
- return lReturn;
- }
-
- long CAutoRect::GetPageInfo(LPDISPATCH /*AGraphic*/, long* StockPages, VARIANT FAR* Names)
- {
- ASSERT(StockPages != NULL);
- ASSERT(Names->vt == VT_ARRAY|VT_BSTR);
-
- // Request pen page and auto page
- *StockPages = PP_STOCK_PEN | PP_STOCK_AUTO;
-
- SAFEARRAYBOUND bound = { 1, 0 };
- if (FAILED(::SafeArrayRedim(Names->parray, &bound)))
- return 0;
-
- CString strCaption;
- strCaption.LoadString(IDS_AUTORECT_CAPTION);
- BSTR bstrCaption = strCaption.AllocSysString();
-
- long lIndex = 0;
- if (FAILED(SafeArrayPutElement(Names->parray, &lIndex, (void*)bstrCaption)))
- {
- ::SysFreeString(bstrCaption);
- return 0;
- }
- return 1;
- }
-
- long CAutoRect::GetWizardInfo(VARIANT FAR* Names)
- {
- // No wizards, nothing to do
- return 0;
- }
-
- long CAutoRect::GetEnumNames(long PropID, VARIANT FAR* Names, VARIANT FAR* Values)
- {
- // Should never be called!
- return 0;
- }
-
- double GetRoundness(IGraphic* pIGraphic)
- {
- double roundness = 50.0;
- Properties* pProps = NULL;
- Property* pProp;
- COleVariant varIndex, varValue;
- if (SUCCEEDED(pIGraphic->get_Properties(&pProps)))
- {
- CString strStr;
- strStr.LoadString(IDS_PROPERTYROUNDESS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_R8)
- {
- roundness = varValue.dblVal;
- }
- pProp->Release();
- }
- pProps->Release();
- }
- return roundness;
- }
-
- void SetRoundness(IGraphic* pIGraphic, double roundness)
- {
- Properties* pProps = NULL;
- Property* pProp;
- COleVariant varIndex;
- if (SUCCEEDED(pIGraphic->get_Properties(&pProps)))
- {
- CString strStr;
- strStr.LoadString(IDS_PROPERTYROUNDESS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- COleVariant varValue;
- varValue.vt = VT_R8;
- varValue.dblVal = roundness;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- }
- pProps->Release();
- }
- }
-
- BOOL CAutoRect::PageControls(LPDISPATCH ThisRegenMethod, LPDISPATCH AGraphic, long PageNumber, BOOL SaveProperties)
- {
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return FALSE;
-
- BOOL bReturn = FALSE;
- Properties* pProps = NULL;
- Property* pProp;
- COleVariant varIndex, varValue;
- if (SUCCEEDED(pIGraphic->get_Properties(&pProps)))
- {
- if (SaveProperties)
- {
- if (m_pRectPage != NULL)
- {
- // Note: the following can fail (for non-rounded rect graphics)
- CString strStr;
- strStr.LoadString(IDS_PROPERTYROUNDESS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- varValue = (const long)m_pRectPage->m_roundness;
- pProp->put_Value(0, &varValue);
- pProp->Release();
- varValue.Clear();
- }
- bReturn = TRUE;
- }
- }
- else
- {
- ASSERT(m_pRectPage == NULL);
- m_pRectPage = new CRectPage();
-
- // Note: the following can fail (for indeterminate values)
- CString strStr;
- strStr.LoadString(IDS_PROPERTYROUNDESS);
- varIndex = LPCTSTR(strStr);
- if (SUCCEEDED(pProps->get_Item(&varIndex, &pProp)))
- {
- if (SUCCEEDED(pProp->get_Value(0, &varValue)) &&
- varValue.vt == VT_R8)
- m_pRectPage->m_roundness = varValue.dblVal;
- pProp->Release();
- varValue.Clear();
- }
- bReturn = TRUE;
- }
- pProps->Release();
- }
-
- pIGraphic->Release();
- return bReturn;
- }
-
- void CAutoRect::PageDone(LPDISPATCH ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- // We're finished with the page
- delete m_pRectPage;
- m_pRectPage = NULL;
- }
-
- BOOL CAutoRect::PropertyPages(LPDISPATCH ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- if (m_pRectPage == NULL)
- return FALSE;
-
- // Run the dialog and get the results
- int nResult = m_pRectPage->DoModal();
- return (nResult == IDOK);
- }
-
- BOOL CAutoRect::Wizard(LPDISPATCH ThisRegenMethod, VARIANT FAR* WizardNumber)
- {
- // No wizards, so just return FALSE.
- return FALSE;
- }
-
- void CAutoRect::OnGeometryChanged(LPDISPATCH AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- }
-
- BOOL CAutoRect::OnGeometryChanging(LPDISPATCH AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- // OK to change our geometry, so just return TRUE.
- return TRUE;
- }
-
- BOOL CAutoRect::OnNewGraphic(LPDISPATCH AGraphic, BOOL Copy)
- {
- // Return FALSE on failure.
- // For copies, usually do nothing.
- if (Copy)
- return TRUE;
-
- // Add vertices, etc. for new graphic here.
-
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return FALSE;
-
- Vertices* pVerts;
- IVertex* pIVertex;
- if (SUCCEEDED(pIGraphic->get_Vertices(&pVerts)))
- {
- COleVariant x;
- COleVariant y;
-
- // First 2 vertices are lower left and upper right corners.
- const double corners[2*2] = { -1.0, -0.5, 1.0, 0.5 };
- for (int i = 0; i < 2*2; )
- {
- x = corners[i++];
- y = corners[i++];
-
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- &f /*penDown*/,
- &t /*selectable*/,
- &f /*snappable*/,
- &f /*editable*/,
- &f /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- }
-
- // Third vertex is rounding handle (calculated)
- double r = 0.5 * GetRoundness(pIGraphic) / 100.0;
- double offset = 0.1 * r;
- x = 1.0 - r;
- y = 0.5 + offset;
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- &f /*penDown*/,
- &f /*selectable*/,
- &f /*snappable*/,
- &f /*editable*/,
- &f /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
-
- // Fourth vertex is rounding handle (editable)
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- &f /*penDown*/,
- &t /*selectable*/,
- &f /*snappable*/,
- &t /*editable*/,
- &f /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
-
- pIGraphic->Release();
- }
- return TRUE;
- }
-
- BOOL CAutoRect::OnCopyGraphic(LPDISPATCH DestGraphic, LPDISPATCH SourceGraphic, VARIANT*)
- {
- // Return FALSE on failure.
- return TRUE;
- }
-
- void CAutoRect::OnPropertyChanged(LPDISPATCH AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- }
-
- BOOL CAutoRect::OnPropertyChanging(LPDISPATCH AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- // OK to change all of our properties, so just return TRUE.
- return TRUE;
- }
-
- void CAutoRect::OnPropertyGet(LPDISPATCH AGraphic, long PropID)
- {
- // No special recalculating of properties needed.
- }
-
- BOOL CAutoRect::Draw(LPDISPATCH AGraphic, LPDISPATCH AView, VARIANT FAR* AMatrix)
- {
- // We don't handle special drawing, so just return FALSE.
- return FALSE;
- }
-
- BOOL GetVertexXYZ(IGraphic* pIGraphic, const long lVertex, double& x, double& y, double& z)
- {
- IVertex* pIVertex = NULL;
- Vertices* pVerts = NULL;
- BOOL bSuccess = FALSE;
- if (SUCCEEDED(pIGraphic->get_Vertices(&pVerts)))
- {
- COleVariant varIndex = lVertex;
- if (SUCCEEDED(pVerts->get_Item(&varIndex, &pIVertex)))
- {
- if (SUCCEEDED(pIVertex->get_X(&x)) &&
- SUCCEEDED(pIVertex->get_Y(&y)) &&
- SUCCEEDED(pIVertex->get_Z(&z)))
- bSuccess = TRUE;
- pIVertex->Release();
- }
- pVerts->Release();
- }
- return bSuccess;
- }
-
- void AddLineChild(Graphics* pGraphics, double x0, double y0, double x1, double y1)
- {
- IGraphic* pChild;
- if (SUCCEEDED(pGraphics->Add(
- &missing /*GraphicType*/,
- &missing /*RegenMethod*/,
- &t /*Inherit*/,
- &missing /*Style*/,
- &missing /*Before*/,
- &missing /*After*/,
- &pChild)))
- {
- pChild->put_Cosmetic(TRUE);
-
- COleVariant x, y;
- Vertices* pVerts = NULL;
- IVertex* pIVertex;
- if (SUCCEEDED(pChild->get_Vertices(&pVerts)))
- {
- x = x0;
- y = y0;
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- &f /*penDown*/,
- &t /*selectable*/,
- &t /*snappable*/,
- &t /*editable*/,
- &t /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- x = x1;
- y = y1;
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- &t /*penDown*/,
- &t /*selectable*/,
- &t /*snappable*/,
- &t /*editable*/,
- &t /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- pVerts->Release();
- }
- pChild->Release();
- }
- }
-
- void AddArcChild(Graphics* pGraphics, double xc, double yc, double r, double start, double end)
- {
- IGraphic* pChild;
- COleVariant type((long)imsiArc);
- if (SUCCEEDED(pGraphics->Add(
- &type /*GraphicType*/,
- &missing /*RegenMethod*/,
- &t /*Inherit*/,
- &missing /*Style*/,
- &missing /*Before*/,
- &missing /*After*/,
- &pChild)))
- {
- pChild->put_Cosmetic(TRUE);
- COleVariant x(xc);
- COleVariant y(yc);
- COleVariant rad(r);
- COleVariant sa(start);
- COleVariant ea(end);
-
- pChild->ArcSet(&x, &y, &z, &rad, &missing, &sa, &ea, &missing);
- pChild->Release();
- }
- }
-
- void CAutoRect::Regen(LPDISPATCH AGraphic)
- {
- IGraphic* pIGraphic = NULL;
- if (FAILED(AGraphic->QueryInterface(IID_IGraphic, (void**)&pIGraphic)))
- return;
-
- long lockCount = 0;
- if (SUCCEEDED(pIGraphic->RegenLock(&lockCount)))
- {
- if (lockCount == 0)
- {
- Graphics* pGraphics = NULL;
- IGraphic* pChild = NULL;
- IVertex* pIVertex = NULL;
- if (SUCCEEDED(pIGraphic->get_Graphics(&pGraphics)))
- {
- COleVariant flags = (const long)GF_COSMETIC;
- pGraphics->Clear(&flags);
-
- // Calculate height, width and radius of corners
-
- double px[4] = { 0.0 };
- double py[4] = { 0.0 };
- double pz[4] = { 0.0 };
- for (int i = 0; i < 4; ++i)
- GetVertexXYZ(pIGraphic, i, px[i], py[i], pz[i]);
-
- BOOL bHandleMoved = !(fabs(px[2] - px[3]) < 0.000001 &&
- fabs(py[2] - py[3]) < 0.000001);
-
- double w = fabs(px[1] - px[0]);
- double h = fabs(py[1] - py[0]);
- double r = (w < h) ? (w/2.0) : (h/2.0);
-
- double roundness;
- if (bHandleMoved)
- {
- if (r == 0.0)
- roundness = 0.0;
- else
- {
- roundness = fabs(px[2] - px[3]) * 100.0 / r;
- if (roundness > 100.0)
- roundness = 100.0;
- }
- SetRoundness(pIGraphic, roundness);
- }
- else
- {
- roundness = GetRoundness(pIGraphic);
- }
- r = r * roundness / 100.0;
-
- // Add child graphics
- // Make sure p[0] < p[1]
- double swap;
- if (px[0] > px[1])
- {
- swap = px[0];
- px[0] = px[1];
- px[1] = swap;
- }
- if (py[0] > py[1])
- {
- swap = py[0];
- py[0] = py[1];
- py[1] = swap;
- }
-
- if (r == 0.0)
- {
- // No rounded corners
- // All children are cosmetic
- if (SUCCEEDED(pGraphics->Add(
- &missing /*GraphicType*/,
- &missing /*RegenMethod*/,
- &t /*Inherit*/,
- &missing /*Style*/,
- &missing /*Before*/,
- &missing /*After*/,
- &pChild)))
- {
- pChild->put_Cosmetic(TRUE);
-
- COleVariant x, y;
- Vertices* pVerts = NULL;
- IVertex* pIVertex;
- if (SUCCEEDED(pChild->get_Vertices(&pVerts)))
- {
- for (int i = 0; i < 4; ++i)
- {
- x = px[(i == 0 || i == 1) ? 0 : 1];
- y = py[(i == 0 || i == 3) ? 0 : 1];
- if (SUCCEEDED(pVerts->Add(&x, &y, &z,
- (i == 0) ? &f : &t /*penDown*/,
- &t /*selectable*/,
- &t /*snappable*/,
- &t /*editable*/,
- &t /*linkable*/,
- &f /*calculated*/,
- &missing /*before*/,
- &missing /*after*/,
- &pIVertex)))
- pIVertex->Release();
- }
- if (SUCCEEDED(pVerts->AddClose(
- &t /*penDown*/,
- &t /*selectable*/,
- &t /*snappable*/,
- &t /*editable*/,
- &t /*linkable*/,
- &f /*calculated*/,
- &pIVertex)))
- pIVertex->Release();
-
- pVerts->Release();
- }
- pChild->Release();
- }
- }
- else
- {
- // Rounded corners
- // We'll make 4 line children and 4 arc children
- AddLineChild(pGraphics, px[0] + r, py[0], px[1] - r, py[0]);
- AddArcChild (pGraphics, px[1] - r, py[0] + r, r, 1.5 * PI, 0.0);
- AddLineChild(pGraphics, px[1], py[0] + r, px[1], py[1] - r);
- AddArcChild (pGraphics, px[1] - r, py[1] - r, r, 0.0, 0.5 * PI);
- AddLineChild(pGraphics, px[1] - r, py[1], px[0] + r, py[1]);
- AddArcChild (pGraphics, px[0] + r, py[1] - r, r, 0.5 * PI, PI);
- AddLineChild(pGraphics, px[0], py[1] - r, px[0], py[0] + r);
- AddArcChild (pGraphics, px[0] + r, py[0] + r, r, PI, 1.5 * PI);
- }
- pGraphics->Release();
- }
- }
- pIGraphic->RegenUnlock(&missing);
- }
- pIGraphic->Release();
- }
-
- BOOL CAutoRect::Initialize(LPDISPATCH ThisRegenMethod)
- {
- // TODO: Add your dispatch handler code here
- return TRUE;
- }
-
- // DUAL_SUPPORT_START
-
- // delegate standard IDispatch methods to MFC IDispatch implementation
- DELEGATE_DUAL_INTERFACE(CAutoRect, DualRect)
-
- // Our method and property functions can generally just
- // delegate back to the methods we generated using
- // ClassWizard. However, if we set up properties to
- // access variables directly, we will need to write the
- // code to get/put the value into the variable.
- STDMETHODIMP CAutoRect::XDualRect::get_Description(BSTR FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetDescription();
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::get_ClassID(BSTR FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetClassID();
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::GetPropertyInfo(VARIANT FAR* Names, VARIANT FAR* Types, VARIANT FAR* IDs, VARIANT FAR* Defaults, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetPropertyInfo(Names, Types, IDs, Defaults);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::GetPageInfo(IDispatch * AGraphic, long FAR* StockPages, VARIANT FAR* Names, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetPageInfo(AGraphic, StockPages, Names);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::GetWizardInfo(VARIANT FAR* Names, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetWizardInfo(Names);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::GetEnumNames(long PropID, VARIANT FAR* Names, VARIANT FAR* Values, long FAR* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->GetEnumNames(PropID, Names, Values);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::PageControls(IDispatch* ThisRegenMethod, IDispatch * AGraphic, long PageNumber, VARIANT_BOOL SaveProperties, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->PageControls(ThisRegenMethod, AGraphic, PageNumber, SaveProperties);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::PageDone(IDispatch * ThisRegenMethod, VARIANT FAR* PageNumber)
- {
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->PageDone(ThisRegenMethod, PageNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::PropertyPages(IDispatch* ThisRegenMethod, VARIANT FAR* PageNumber, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->PropertyPages(ThisRegenMethod, PageNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::Wizard(IDispatch* ThisRegenMethod, VARIANT FAR* WizardNumber, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Wizard(ThisRegenMethod, WizardNumber);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnGeometryChanged(IDispatch * AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew)
- {
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnGeometryChanged(AGraphic, GeomID, ParamOld, ParamNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnGeometryChanging(IDispatch * AGraphic, long GeomID, VARIANT FAR* ParamOld, VARIANT FAR* ParamNew, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnGeometryChanging(AGraphic, GeomID, ParamOld, ParamNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnNewGraphic(IDispatch * AGraphic, VARIANT_BOOL Copy, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnNewGraphic(AGraphic, Copy);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnCopyGraphic(IDispatch* CopyGraphic, IDispatch* SourceGraphic, VARIANT* Matrix, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnCopyGraphic(CopyGraphic, SourceGraphic, Matrix);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnPropertyChanged(IDispatch * AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew)
- {
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnPropertyChanged(AGraphic, PropID, ValueOld, ValueNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnPropertyChanging(IDispatch * AGraphic, long PropID, VARIANT FAR* ValueOld, VARIANT FAR* ValueNew, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->OnPropertyChanging(AGraphic, PropID, ValueOld, ValueNew);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::OnPropertyGet(IDispatch * AGraphic, long PropID)
- {
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->OnPropertyGet(AGraphic, PropID);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::Draw(IDispatch * AGraphic, IDispatch * AView, VARIANT FAR* AMatrix, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Draw(AGraphic, AView, AMatrix);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::Regen(IDispatch* AGraphic)
- {
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- pThis->Regen(AGraphic);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
- STDMETHODIMP CAutoRect::XDualRect::Initialize(IDispatch* ThisRegenMethod, VARIANT_BOOL* retval)
- {
- if (retval == NULL)
- return E_POINTER;
-
- METHOD_PROLOGUE(CAutoRect, DualRect)
-
- TRY_DUAL(IID_ISmartObjectServer)
- {
- *retval = pThis->Initialize(ThisRegenMethod);
- return S_OK;
- }
- CATCH_ALL_DUAL
- }
-
-
- // Implement ISupportErrorInfo to indicate we support the
- // OLE Automation error handler.
- IMPLEMENT_DUAL_ERRORINFO(CAutoRect, IID_ISmartObjectServer)
-
- // DUAL_SUPPORT_END
-